<?php


namespace api\modules\v1\controllers;

use api\controllers\OnAuthController;
use common\models\byxcx\Cate;
use common\models\byxcx\Chart;
use common\models\byxcx\Article;
use Yii;
class MenuController extends OnAuthController
{
    public $modelClass = '';
    protected $authOptional = ['nav','banner','banne','bann','article','articl'];
//二级导航
    public function actionNav(){
        $data =Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_chart}} b','b.cate_id=a.id')
            ->select('a.title,a.pid,b.cover')
            ->where(['pid'=>36])
            ->asarray()
            ->all();
        if ($data) {
            return $data;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }
    //优势
    public function actionBanner(){
        $id =Yii::$app->request->get();
        $data=Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_chart}} b','b.cate_id=a.id')
            ->select('b.title,b.description,b.cover')
            ->where(['tag'=>1,'pid'=>$id])
            ->asArray()
            ->all();
        if ($data) {
            return $data;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }
    //质量保证
    public function actionBanne(){
        $id =Yii::$app->request->get();
        $data=Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_chart}} b','b.cate_id=a.id')
            ->select('b.title,b.description,b.cover,b.cate_id')
            ->where(['tag'=>2,'pid'=>$id])
            ->asArray()
            ->all();
        $a = array_column($data,'cate_id');
        $arr =Cate::find()
            ->where(['id'=>$a[0]])
            ->select('title')
            ->asArray()
            ->one();
        $b = array_merge($data,$arr);
        if ($b) {
            return $b;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }
    //柏萤发展历程
    public function actionBann(){
        $id =Yii::$app->request->get();
        $data=Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_chart}} b','b.cate_id=a.id')
            ->select('b.title,b.description,b.cover,b.cate_id')
            ->where(['tag'=>3,'pid'=>$id])
            ->asArray()
            ->all();
        $a = array_column($data,'cate_id');
        $arr =Cate::find()
            ->where(['id'=>$a[0]])
            ->select('title')
            ->asArray()
            ->one();
        $b = array_merge($data,$arr);
        if ($b) {
            return $b;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }
    //摘要
    public function actionArticle(){
        $id =Yii::$app->request->get();
        $data=Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_article}} b','b.cate_id=a.id')
            ->select('b.title,b.description,b.cover,b.content')
            ->where(['tag'=>1,'pid'=>$id])
            ->asArray()
            ->all();
        if ($data) {
            return $data;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }
    //行业定制
    public function actionArticl(){
        $id =Yii::$app->request->get();
        $data=Cate::find()
            ->from('{{%byxcx_cate}} a')
            ->join('join','{{%byxcx_article}} b','b.cate_id=a.id')
            ->select('b.title,b.description,b.cover,b.content')
            ->where(['tag'=>2,'pid'=>$id])
            ->asArray()
            ->all();
        if ($data) {
            return $data;
        } else {
            return ['code' => 0, 'msg' => "失败", 'data' => []];
        }
    }

}